import React, { Component } from 'react'
import Son from './components/Son';

export default class App extends Component {
    state = {
        count:100
    }
    /**
     * 组件挂载后执行
     * componentDidMount 做什么
     * 1. 发送ajax请求，获取服务器端的数据
     * 2. 订阅消息
     * 3. 添加事件监听
     * 4. 开启定时器
     */
    componentDidMount(){
        console.log('App componentDidMount');
    }
    constructor(){
        super();
        console.log('App constructor');
    }
    componentDidUpdate(){
        console.log('App componentDidUpdate');
    }
    render() {
        console.log('App render');
        return (
            <div>
                <h3>App</h3>
                <p>App state count : {this.state.count}</p>
                <button onClick={()=>{
                    this.setState({
                        count: this.state.count + 1
                    })
                }}>setState</button>

                <button onClick={()=>{
                    this.state.count += 3;
                    this.forceUpdate();// 强制更新
                }}>forceUpdate</button>
                <hr/>
                <Son count={this.state.count}/>
            </div>
        )
    }
    
}
